//
//  testView.m
//  garbageclient
//
//  Created by Wang Wu on 11-8-19.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "testView.h"
#import "commondef.h"
#import "SBJson.h"
#import "mainViewTableCall.h"
@implementation testView

- (void)dealloc
{
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        CGRect screenrc = [[UIScreen mainScreen] applicationFrame];
        
                
        webdatabuf = [[NSMutableData alloc] initWithLength:0];

        
        NSString *urlString = [NSString stringWithFormat:@"http://appsearch.sagetouch.com/app123/ipadservice/6-0-1-0-0.html"];
        NSURL *url = [NSURL URLWithString:urlString];
        
        NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
        NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        [connection release];
        [request release];
        
        tableview = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, NAV_HEIGHT, 
                                                                  screenrc.size.width,
                                                                  screenrc.size.height - NAV_HEIGHT - BTN_HEIGHT)];
        [self addSubview:tableview];
        [tableview setDelegate:self];
        [tableview setDataSource:self];

    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return TVC_HEIGHT;
}

-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ri"];
    
    if(cell == nil)
    {
        cell = [[mainViewTableCall alloc]initWithDictionary:[results objectAtIndex:indexPath.section]];
    }
    return  cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 30;
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{
    [webdatabuf appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)aConn
{
	NSString *jsonString = [[NSString alloc] initWithData:webdatabuf encoding:NSUTF8StringEncoding];
    
	results = [jsonString JSONValue];
    
	[jsonString release]; 
    
}
@end
